package com.jali.crud.controller;

import com.jali.crud.bean.JaScoreLog;
import com.jali.crud.bean.Msg;
import com.jali.crud.service.JaScoreLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jali.common.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @author jali
 * @create 2019-01-27 7:19
 */
@Controller
public class JaScoreLogController  {

    @Autowired
    JaScoreLogService jaScoreLogService;

    @RequestMapping("/jaScoreUseList")
    public String toJaScoreUseList(){
        return "jaScoreUseList";
    }

    @RequestMapping("/scoreLog")
    @ResponseBody
    public Msg getScoreLogList(@RequestParam(value = "pn",defaultValue = "1") Integer pn){
            //在查询之前只需要调用，传入页码，以及每页的大小
            PageHelper.startPage(pn,10);
            List<JaScoreLog> jaScoreLogList = jaScoreLogService.selectScoreLogList(null);
            for(JaScoreLog jaScoreLog : jaScoreLogList){
                jaScoreLog.setTime(DateUtil.formatToString(jaScoreLog.getTime()));
            }
            //使用pageInfo包装查询后的结果，只需要将pageInfo交给页面就行了
            //封装了详细的分页详细，包括有我们查询出来的数据，传入连续显示的页数
            PageInfo pageInfo = new PageInfo(jaScoreLogList,5);
            return Msg.success().add("pageInfo",pageInfo);
    }

}
